<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />


    <div style="height:47px;"></div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDrawer(1)">关 闭</el-button>
      <!-- <el-button @click="closeDrawer(2)" type="primary">签收入库</el-button> -->
      <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">签收入库</multiuse-button>
    </div>
  </div>
</template>
<script>
import moment from 'moment'
import {getList,getDetail,postSave,getStorageList} from '@/api/dealerSale/InventoryManagement/SignWarehousing/index.js'
export default {
  data(){
    this.saveData=null;
    return{
      formList:this.createdFrom(),
    }
  },
  props:['rowData'],
  components: {

  },
  created(){
    this.getDetail(this.rowData);
    this.getStorageList()
  },
  methods:{
    createdFrom(){
      return [


        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'seriesCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '配置名称',
          fieldName: 'packageCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '选装名称',
          fieldName: 'optionCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '内饰',
          fieldName: 'trimCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '外色',
          fieldName: 'colorCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '产品代码',
          fieldName: 'productCode',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'dlrWarehouseId',
          placeholder: '请选择',
          itemList:[],
          rules: [{ required: true, message: '请选择', trigger: 'change' }],
        },
        {
          type: 'INPUT',
          label: '收车人',
          fieldName: 'receiver',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '销售订单号',
          fieldName: 'doNo',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'DATE',
          label: '收车时间',
          fieldName: 'receiveDate',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'DATE',
          label: '发运日期',
          fieldName: 'startDeliveryDate',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'INPUT',
          label: '发运单号',
          fieldName: 'transNo',
          placeholder: '请输入',
          disabled:true,
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'receiveRemark',
          selfCols:3
        },

      ]
    },
    async getStorageList(){
      let res=await getStorageList()
      console.log(res.data)
      this.formList.map(x=>{
        if(x.fieldName=='dlrWarehouseId'){
          x.itemList=res.data.list.map(x=>({text:x.warehouseName,value:x.warehouseId}))
        }
      })
    },
    async getDetail(data){
      let res=await getDetail({id:data.doId})
      for (let i in res.data) {
      this.formList.map(x => {
        if(x.fieldName=='receiveDate'){
          x.initialValue=res.data.receiveDate?res.data.receiveDate:moment().format('YYYY-MM-DD HH:mm:ss');
        }else if (i == x.fieldName) {
            x.initialValue = res.data[i];
          }
        });
      }
    },
    changeHandle(val){
      this.saveData=val;
    },

    async closeDrawer(type){
      if(type==1){
        this.$emit('close')
      }else{
        this.$refs.from.SUBMIT_FORM();
        console.log(this.saveData, 'this.saveData');
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          json.doId=this.rowData.doId;
          json.vehicleId=this.rowData.vehicleId
          let res = await postSave(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '签收入库成功',
              type: 'success'
            });
            this.$emit('close', json);
          }else{
            this.saveData=null;
          }
        }

      }
    }

  }
}
</script>
